home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / AIncludes / Math64.a < prev    next >
Encoding:
Text File  |  1997-08-12  |  11.7 KB  |  487 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Math64.a
  3. ;
  4. ;    Contains:    64-bit integer math Interfaces.
  5. ;
  6. ;    Version:    Technology:    System 7.5
  7. ;                Release:    Universal Interfaces 3.0.1
  8. ;
  9. ;    Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved
  10. ;
  11. ;    Bugs?:        Please include the the file and version information (from above) with
  12. ;                the problem description.  Developers belonging to one of the Apple
  13. ;                developer programs can submit bug reports to:
  14. ;
  15. ;                    devsupport@apple.com
  16. ;
  17. ;
  18.     IF &TYPE('__MATH64__') = 'UNDEFINED' THEN
  19. __MATH64__ SET 1
  20.  
  21.     IF &TYPE('__TYPES__') = 'UNDEFINED' THEN
  22.     include 'Types.a'
  23.     ENDIF
  24.  
  25.  
  26. ; --------------------------------------------------------------------------------
  27. ;                These routines are intended to provide C software support for
  28. ;                64 bit integer types.  Their behavior should mimic anticipated
  29. ;                64 bit hardware. This implementation should replace use of the
  30. ;                "wide" type found in PowerPC.
  31. ;
  32. ;    The following routines are available for performing math on 64-bit integers:
  33. ;    
  34. ;    S64Max
  35. ;                Returns the largest representable SInt64.
  36. ;    S64Min
  37. ;                Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  38. ;                (absolute value) of this number is not representable in an SInt64.
  39. ;                That means that S64Negate(S64Min) is not representable (in fact,
  40. ;                it returns S64Min).
  41. ;    S64Add
  42. ;                Adds two integers, producing an integer result.  If an overflow
  43. ;                occurs the result is congruent mod (2^64) as if the operands and
  44. ;                result were unsigned.  No overflow is signaled.
  45. ;    
  46. ;    S64Subtract
  47. ;                Subtracts two integers, producing an integer result.  If an overflow
  48. ;                occurs the result is congruent mod (2^64) as if the operands and
  49. ;                result were unsigned.  No overflow is signaled.
  50. ;
  51. ;    S64Negate
  52. ;                Returns the additive inverse of a signed number (i.e. it returns
  53. ;                0 - the number).  S64Negate (S64Min) is not representable (in fact,
  54. ;                it returns S64Min).
  55. ;    
  56. ;    S64Absolute
  57. ;                Returns the absolute value of the number (i.e. the number if
  58. ;                it is positive, or 0 - the number if it is negative).
  59. ;                See S64Negate above.
  60. ;                
  61. ;    S64Multiply
  62. ;                Multiplies two signed numbers, producing a signed result.  Overflow
  63. ;                is ignored and the low-order part of the product is returned.  The
  64. ;                sign of the result is not guaranteed to be correct if the magnitude
  65. ;                of the product is not representable.
  66. ;    S64Divide
  67. ;                Divides dividend by divisor, returning the quotient.  The remainder
  68. ;                is returned in *remainder if remainder (the pointer) is non-NULL.
  69. ;                The sign of the remainder is the same as the sign of the dividend
  70. ;                (i.e. it takes the absolute values of the operands, does the division,
  71. ;                then fixes the sign of the quotient and remainder).  If the divisor
  72. ;                is zero, then S64Max() will be returned (or S64Min() if the dividend
  73. ;                is negative), and the remainder will be the dividend; no error is
  74. ;                reported.
  75. ;    
  76. ;    S64Set
  77. ;                Given an SInt32, returns an SInt64 with the same value.  Use this
  78. ;                routine instead of coding 64-bit constants (at least when the
  79. ;                constant will fit in an SInt32).
  80. ;    
  81. ;    S64SetU
  82. ;                Given a UInt32, returns a SInt64 with the same value.
  83. ;    
  84. ;    S64Compare
  85. ;                Given two signed numbers, left and right, returns an
  86. ;                SInt32 that compares with zero the same way left compares with
  87. ;                right.  If you wanted to perform a comparison on 64-bit integers
  88. ;                of the form:
  89. ;                        operand_1 <operation> operand_2
  90. ;                then you could use an expression of the form:
  91. ;                        xxxS64Compare(operand_1,operand_2) <operation> 0
  92. ;                to test for the same condition.
  93. ;                
  94. ;                CAUTION: DO NOT depend on the exact value returned by this routine.
  95. ;                Only the sign (i.e. positive, zero, or negative) of the result is
  96. ;                guaranteed.
  97. ;
  98. ;    S64And, S64Or, S64Eor and S64Not
  99. ;    
  100. ;                Return Boolean (1 or 0) depending on the outcome of the logical
  101. ;                operation.
  102. ;
  103. ;    S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  104. ;    
  105. ;                Return the Bitwise result.
  106. ;                
  107. ;    S64ShiftRight and S64ShiftLeft
  108. ;    
  109. ;                The lower 7 bits of the shift argument determines the amount of 
  110. ;                shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  111. ;                is a logical shift.
  112. ;
  113. ;    SInt64ToLongDouble
  114. ;                
  115. ;                Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  116. ;                long doubles, thus, the binary -> decimal conversion routines
  117. ;                in fp.h can be used to achieve SInt64 -> long double -> decimal
  118. ;                conversions.
  119. ;                
  120. ;    LongDoubleToSInt64
  121. ;    
  122. ;                Converts a long double to a SInt64.  Any decimal string that fits
  123. ;                into a SInt64 can be converted exactly into a long double, using the
  124. ;                conversion routines found in fp.h.  Then this routine can be used
  125. ;                to complete the conversion to SInt64.
  126. ;                
  127. ;    SInt64ToWide
  128. ;    
  129. ;                Converts a SInt64 to a wide struct.  If SInt64 is implemented
  130. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  131. ;                implememnted as a long long, it casts the long long into a 
  132. ;                wide struct.
  133. ;    
  134. ;    WideToSInt64
  135. ;    
  136. ;                Converts a wide struct into a SInt64.  If SInt64 is implemented
  137. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  138. ;                implememnted as a long long, it reads the struct into a long long.
  139. ;    
  140. ;    
  141. ;    The corresponding UInt64 routines are also included.
  142. ;    
  143. ;--------------------------------------------------------------------------------
  144.  
  145.  
  146. ;
  147. ; extern SInt64 S64Max(void )
  148. ;
  149.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  150.         IMPORT_CFM_FUNCTION S64Max
  151.     ENDIF
  152.  
  153. ;
  154. ; extern SInt64 S64Min(void )
  155. ;
  156.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  157.         IMPORT_CFM_FUNCTION S64Min
  158.     ENDIF
  159.  
  160. ;
  161. ; extern SInt64 S64Add(SInt64 x, SInt64 y)
  162. ;
  163.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  164.         IMPORT_CFM_FUNCTION S64Add
  165.     ENDIF
  166.  
  167. ;
  168. ; extern SInt64 S64Subtract(SInt64 left, SInt64 right)
  169. ;
  170.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  171.         IMPORT_CFM_FUNCTION S64Subtract
  172.     ENDIF
  173.  
  174. ;
  175. ; extern SInt64 S64Negate(SInt64 value)
  176. ;
  177.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  178.         IMPORT_CFM_FUNCTION S64Negate
  179.     ENDIF
  180.  
  181. ;
  182. ; extern SInt64 S64Absolute(SInt64 value)
  183. ;
  184.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  185.         IMPORT_CFM_FUNCTION S64Absolute
  186.     ENDIF
  187.  
  188. ;
  189. ; extern SInt64 S64Multiply(SInt64 xparam, SInt64 yparam)
  190. ;
  191.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  192.         IMPORT_CFM_FUNCTION S64Multiply
  193.     ENDIF
  194.  
  195. ;
  196. ; extern SInt64 S64Divide(SInt64 dividend, SInt64 divisor, SInt64 *remainder)
  197. ;
  198.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  199.         IMPORT_CFM_FUNCTION S64Divide
  200.     ENDIF
  201.  
  202. ;
  203. ; extern SInt64 S64Set(SInt32 value)
  204. ;
  205.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  206.         IMPORT_CFM_FUNCTION S64Set
  207.     ENDIF
  208.  
  209. ;
  210. ; extern SInt64 S64SetU(UInt32 value)
  211. ;
  212.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  213.         IMPORT_CFM_FUNCTION S64SetU
  214.     ENDIF
  215.  
  216. ;
  217. ; extern SInt32 S32Set(SInt64 value)
  218. ;
  219.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  220.         IMPORT_CFM_FUNCTION S32Set
  221.     ENDIF
  222.  
  223. ;
  224. ; extern int S64Compare(SInt64 left, SInt64 right)
  225. ;
  226.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  227.         IMPORT_CFM_FUNCTION S64Compare
  228.     ENDIF
  229.  
  230. ;
  231. ; extern Boolean S64And(SInt64 left, SInt64 right)
  232. ;
  233.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  234.         IMPORT_CFM_FUNCTION S64And
  235.     ENDIF
  236.  
  237. ;
  238. ; extern Boolean S64Or(SInt64 left, SInt64 right)
  239. ;
  240.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  241.         IMPORT_CFM_FUNCTION S64Or
  242.     ENDIF
  243.  
  244. ;
  245. ; extern Boolean S64Eor(SInt64 left, SInt64 right)
  246. ;
  247.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  248.         IMPORT_CFM_FUNCTION S64Eor
  249.     ENDIF
  250.  
  251. ;
  252. ; extern Boolean S64Not(SInt64 value)
  253. ;
  254.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  255.         IMPORT_CFM_FUNCTION S64Not
  256.     ENDIF
  257.  
  258. ;
  259. ; extern SInt64 S64BitwiseAnd(SInt64 left, SInt64 right)
  260. ;
  261.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  262.         IMPORT_CFM_FUNCTION S64BitwiseAnd
  263.     ENDIF
  264.  
  265. ;
  266. ; extern SInt64 S64BitwiseOr(SInt64 left, SInt64 right)
  267. ;
  268.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  269.         IMPORT_CFM_FUNCTION S64BitwiseOr
  270.     ENDIF
  271.  
  272. ;
  273. ; extern SInt64 S64BitwiseEor(SInt64 left, SInt64 right)
  274. ;
  275.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  276.         IMPORT_CFM_FUNCTION S64BitwiseEor
  277.     ENDIF
  278.  
  279. ;
  280. ; extern SInt64 S64BitwiseNot(SInt64 value)
  281. ;
  282.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  283.         IMPORT_CFM_FUNCTION S64BitwiseNot
  284.     ENDIF
  285.  
  286. ;
  287. ; extern SInt64 S64ShiftRight(SInt64 value, UInt32 shift)
  288. ;
  289.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  290.         IMPORT_CFM_FUNCTION S64ShiftRight
  291.     ENDIF
  292.  
  293. ;
  294. ; extern SInt64 S64ShiftLeft(SInt64 value, UInt32 shift)
  295. ;
  296.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  297.         IMPORT_CFM_FUNCTION S64ShiftLeft
  298.     ENDIF
  299.  
  300. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  301. ;
  302.  
  303. ;
  304. ; extern long double SInt64ToLongDouble(SInt64 value)
  305. ;
  306.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  307.         IMPORT_CFM_FUNCTION SInt64ToLongDouble
  308.     ENDIF
  309.  
  310. ;
  311. ; extern SInt64 LongDoubleToSInt64(long double value)
  312. ;
  313.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  314.         IMPORT_CFM_FUNCTION LongDoubleToSInt64
  315.     ENDIF
  316.  
  317. ;
  318. ; extern UInt64 U64Max(void )
  319. ;
  320.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  321.         IMPORT_CFM_FUNCTION U64Max
  322.     ENDIF
  323.  
  324. ;
  325. ; extern UInt64 U64Add(UInt64 x, UInt64 y)
  326. ;
  327.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  328.         IMPORT_CFM_FUNCTION U64Add
  329.     ENDIF
  330.  
  331. ;
  332. ; extern UInt64 U64Subtract(UInt64 left, UInt64 right)
  333. ;
  334.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  335.         IMPORT_CFM_FUNCTION U64Subtract
  336.     ENDIF
  337.  
  338. ;
  339. ; extern UInt64 U64Multiply(UInt64 xparam, UInt64 yparam)
  340. ;
  341.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  342.         IMPORT_CFM_FUNCTION U64Multiply
  343.     ENDIF
  344.  
  345. ;
  346. ; extern UInt64 U64Divide(UInt64 dividend, UInt64 divisor, UInt64 *remainder)
  347. ;
  348.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  349.         IMPORT_CFM_FUNCTION U64Divide
  350.     ENDIF
  351.  
  352. ;
  353. ; extern UInt64 U64Set(SInt32 value)
  354. ;
  355.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  356.         IMPORT_CFM_FUNCTION U64Set
  357.     ENDIF
  358.  
  359. ;
  360. ; extern UInt64 U64SetU(UInt32 value)
  361. ;
  362.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  363.         IMPORT_CFM_FUNCTION U64SetU
  364.     ENDIF
  365.  
  366. ;
  367. ; extern UInt32 U32SetU(UInt64 value)
  368. ;
  369.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  370.         IMPORT_CFM_FUNCTION U32SetU
  371.     ENDIF
  372.  
  373. ;
  374. ; extern int U64Compare(UInt64 left, UInt64 right)
  375. ;
  376.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  377.         IMPORT_CFM_FUNCTION U64Compare
  378.     ENDIF
  379.  
  380. ;
  381. ; extern Boolean U64And(UInt64 left, UInt64 right)
  382. ;
  383.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  384.         IMPORT_CFM_FUNCTION U64And
  385.     ENDIF
  386.  
  387. ;
  388. ; extern Boolean U64Or(UInt64 left, UInt64 right)
  389. ;
  390.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  391.         IMPORT_CFM_FUNCTION U64Or
  392.     ENDIF
  393.  
  394. ;
  395. ; extern Boolean U64Eor(UInt64 left, UInt64 right)
  396. ;
  397.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  398.         IMPORT_CFM_FUNCTION U64Eor
  399.     ENDIF
  400.  
  401. ;
  402. ; extern Boolean U64Not(UInt64 value)
  403. ;
  404.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  405.         IMPORT_CFM_FUNCTION U64Not
  406.     ENDIF
  407.  
  408. ;
  409. ; extern UInt64 U64BitwiseAnd(UInt64 left, UInt64 right)
  410. ;
  411.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  412.         IMPORT_CFM_FUNCTION U64BitwiseAnd
  413.     ENDIF
  414.  
  415. ;
  416. ; extern UInt64 U64BitwiseOr(UInt64 left, UInt64 right)
  417. ;
  418.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  419.         IMPORT_CFM_FUNCTION U64BitwiseOr
  420.     ENDIF
  421.  
  422. ;
  423. ; extern UInt64 U64BitwiseEor(UInt64 left, UInt64 right)
  424. ;
  425.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  426.         IMPORT_CFM_FUNCTION U64BitwiseEor
  427.     ENDIF
  428.  
  429. ;
  430. ; extern UInt64 U64BitwiseNot(UInt64 value)
  431. ;
  432.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  433.         IMPORT_CFM_FUNCTION U64BitwiseNot
  434.     ENDIF
  435.  
  436. ;
  437. ; extern UInt64 U64ShiftRight(UInt64 value, UInt32 shift)
  438. ;
  439.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  440.         IMPORT_CFM_FUNCTION U64ShiftRight
  441.     ENDIF
  442.  
  443. ;
  444. ; extern UInt64 U64ShiftLeft(UInt64 value, UInt32 shift)
  445. ;
  446.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  447.         IMPORT_CFM_FUNCTION U64ShiftLeft
  448.     ENDIF
  449.  
  450. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  451. ;
  452.  
  453. ;
  454. ; extern long double UInt64ToLongDouble(UInt64 value)
  455. ;
  456.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  457.         IMPORT_CFM_FUNCTION UInt64ToLongDouble
  458.     ENDIF
  459.  
  460. ;
  461. ; extern UInt64 LongDoubleToUInt64(long double value)
  462. ;
  463.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  464.         IMPORT_CFM_FUNCTION LongDoubleToUInt64
  465.     ENDIF
  466.  
  467. ;
  468. ; extern SInt64 UInt64ToSInt64(UInt64 value)
  469. ;
  470.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  471.         IMPORT_CFM_FUNCTION UInt64ToSInt64
  472.     ENDIF
  473.  
  474. ;
  475. ; extern UInt64 SInt64ToUInt64(SInt64 value)
  476. ;
  477.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  478.         IMPORT_CFM_FUNCTION SInt64ToUInt64
  479.     ENDIF
  480.  
  481.  
  482.  
  483.     ENDIF ; __MATH64__ 
  484.  
  485.